<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="function.jsp"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组织架构导入</title>
    <link rel="stylesheet" href="/css/public.css?cache=<%=Math.random()%>">
    <link  href="../../hos_manage/images/favicon.ico?cache=<%=Math.random()%>" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="../../css/palace/address/address_import.css?a=<%=Math.random()%>">
    <script src="/js/jquery-1.9.1.min.js"></script>
</head>
<body id="app" v-cloak>
<%@ include file="../../header.jsp"%>
<!--内容-->
<div class="containerone">
    <%@ include file="../../left_menu.jsp"%>
    <!--右边内容-->
    <div class="right_cont">
        <!--右边导航下面内容-->
        <div class="address-import">
            <div class="title">
                <div class="address-left show-block note">
                    <span class="hover" @click="homePage()">首页</span>
                    <span class="left-distance">></span>
                    <span class="left-distance">组织架构列表</span>
                    <span class="left-distance">></span>
                    <span class="left-distance">批量导入</span>
                </div>
            </div>
            <div class="container">
                <div class="position">
                    <div class="show-block address-book-right">
                        <div class="data-form show-margin-left">
                            <div class="standard">请按照我们提供的<a href="http://file.eeesys.com/attach/1497853498.xls"><span class="import">标准模板</span></a>填写</div>
                            <div class="excel-image">
                                <img src="../../images/palace/address/excel.png">
                            </div>
                            <div class="center">
                                <div class="show-block show-left">
                                    <div class="upload-address">上传组织架构</div>
                                    <div class="show-excel-address show-block" v-html="filename"></div>
                                    <div class="file-watch show-block">
                                        <input type="file" class="input-file" @change="changeFile($event)">
                                        <div class="watch center">浏览</div>
                                    </div>
                                    <div class="upload show-block center" @click="submit()" v-html="loginText"></div>
                                    <div class="format">* 只支持XLS格式</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<dangertip v-if="dangerTipShow" :title="dangerTitle"></dangertip>
<messagetip v-if="messageTipShow" :title="messageTitle"></messagetip>
</body>
<%@ include file="/components/danger.jsp"%>
<%@ include file="/components/message.jsp"%>
<script src="/js/components/upload.js"></script>
<script>
    var HOSPITAL = "${user.hospital}";
    new Vue({
        el: "#app",
        data: {
            filename: "",
            input: undefined,
            dangerTipShow: false,
            dangerTitle: "",
            messageTipShow: false,
            messageTitle: "",
            loginText: "上传",
        },
        methods: {
            danger: function(title) {
                this.dangerTitle = title;
                this.dangerTipShow = true;
            },
            message: function(title) {
                this.messageTitle = title;
                this.messageTipShow = true;
            },
            homePage: function () {
                location.href = "../../index.jsp";
            },
            // 当文件改变时
            changeFile: function(event) {
                this.input = undefined;
                this.filename = "";
                var input = event.target;
                var file = input.files[0];
                if (!file) {
                    this.filename = "";
                    this.input = "";
                    return;
                }
                var filename = file.name;
                var size = file.size;
                if (size > 20000000) {
                    this.danger("文件过大，请重新选择");
                    return;
                }
                if (!/\.xls$/.test(filename)) {
                    this.danger("文件类型有误，重新上传");
                    return;
                }
                this.filename = filename;
                this.input = input;
            },
            submit: function() {
                var _this = this;
                if (this.input && this.input) {
                    _this.loginText = "上传中...";
                    fileUpLoadMulti([this.input], function (res) {
                        if (res.errcode == 0) {
                            var url = res.result[0];
                            $.ajax({
                                type: 'POST',
                                url: location.href,
                                data: {
                                    act: "organizationExcel",
                                    hospital: HOSPITAL,
                                    urlFileName: url,
                                    deptType: "20",
                                },
                                success: function(res) {
                                    _this.loginText = "上传";
                                    res = JSON.parse(res);
                                    if (res.errcode == 0) {
                                        _this.message("上传成功");
                                        setTimeout(function () {
                                            history.go(-1);
                                        }, 1000)
                                    } else {
                                        _this.danger(res.errmsg);
                                    }
                                },
                            });
                        } else {
                            _this.danger(res.errmsg);
                        }
                    });
                } else {
                    this.danger("请选择需要上传的组织架构的excel!")
                }
            }
        },
        events: {
            dangerTipOver: function() {
                this.dangerTipShow = false;
            },
            messageTipOver: function() {
                this.messageTipShow = false;
            },
        },
        ready: function() {
            $.ajax({
                type: 'POST',
                url: location.href,
                data: {
                    act: "organizationCheck",
                    hospital: HOSPITAL,
                    deptType: "20",
                },
                async: false,
                success: function(res) {
                    res = JSON.parse(res);
                    if (res.errcode == 0) {
                        // 组织架构有跳转到导入组织架构
                        if (res.data != 0) {
                            locationReplace("organization");
                        }
                    } else {
                        _this.danger(res.errmsg);
                    }
                },
            });
        },
        components: {
            dangertip: dangerTip,
            messagetip: messageTip,
        },
    });
</script>
</html>
